#include "filebufferwithsignals.h"
//#include <QThread>
//#include <QDebug>

void FileBufferWithSignals::loadFile(QString fName)
{
    FileBuffer::loadFile(fName);
//    qDebug() << "signal emission in thread" << thread()->currentThreadId();
    if(errorString.isNull()){
        emit fileLoaded(fName, fileSize);
    } else {
        emit fileLoadingError(fName, errorString, state);
    }
}

void FileBufferWithSignals::saveFile(QString fName)
{
    FileBuffer::saveFile(fName);
    if(errorString.isNull()){
        emit fileSaved(fName);
    } else {
        emit fileSavingError(fName, errorString);
    }

}

void FileBufferWithSignals::clearData()
{
    FileBuffer::clearData();
    emit dataCleared();
}

void FileBufferWithSignals::setState(State newState)
{
    switch (newState) {
    case LOADING:
        emit beginFileLoading(fileSize);
        break;
    case SAVING:
        emit beginFileSaving(fileSize);
        break;
    default:
        break;
    }
    FileBuffer::setState(newState);
}
